class Node:
    def __init__(self, nums, begin, end):
        self.begin=begin
        self.end=end
        self.mid=(begin+end)//2
        if begin+1==end:
            self.left=None
            self.right=None
            self.sum=nums[begin]
        else:
            self.left=Node(nums, begin, self.mid)
            self.right=Node(nums, self.mid, end)
            self.sum=self.left.sum+self.right.sum
    def sumRange(self, begin, end):
        if self.begin==begin and self.end==end: return self.sum
        elif end<=self.mid: return self.left.sumRange(begin,end)
        elif begin>=self.mid: return self.right.sumRange(begin,end)
        else: return self.left.sumRange(begin,self.mid)+self.right.sumRange(self.mid,end)
    def update(self, i, dif):
        if not (self.begin<=i<self.end): return
        self.sum += dif
        if self.end-self.begin>1:
            if i>=self.mid: self.right.update(i,dif)
            else: self.left.update(i,dif)

class NumArray(object):
    def __init__(self, nums):
        """
        initialize your data structure here.
        :type nums: List[int]
        """
        self.nums = nums
        self.root = Node(self.nums, 0, len(self.nums)) if nums else None

    def update(self, i, val):
        """
        :type i: int
        :type val: int
        :rtype: int
        """
        self.root.update(i,val-self.nums[i])
        self.nums[i]=val

    def sumRange(self, i, j):
        """
        sum of elements nums[i..j], inclusive.
        :type i: int
        :type j: int
        :rtype: int
        """
        return self.root.sumRange(i,j+1)


# Your NumArray object will be instantiated and called as such:
numArray = NumArray([1,2,3,4,5])
print(numArray.sumRange(0, 1))
numArray.update(1, 10)
print(numArray.sumRange(1, 2))